package com.inspectortime.webapp.inspector.reports;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.inspectortime.domain.InspectorCompany;
import com.inspectortime.repository.Repository;
import com.inspectortime.webapp.util.CustomCalendarEditor;
import com.inspectortime.webapp.util.HttpSessionUtils;

public abstract class ReportsController extends SimpleFormController {
	
private static Log log = LogFactory.getLog(ReportsController.class);
	
	private Repository repository;
	
	protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
		DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
		df.setLenient(true);
		CustomCalendarEditor editor = new CustomCalendarEditor(df, true);
		binder.registerCustomEditor(Calendar.class, editor);
	}

	protected Map referenceData(HttpServletRequest request) throws Exception {
		InspectorCompany company = HttpSessionUtils.retrieveLoggedInCompany(request, repository);
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("inspectorCompany", company);
		return data;
	}
	
	
	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	public Repository getRepository() {
		return repository;
	}


}
